<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/26 0026
 * Time: 下午 18:00
 */
namespace app\admin\controller;

use think\Db;
use app\admin\controller\Permissions;
class Notice extends Permissions
{
    public function index()
    {
        if ($this->request->isPost()) {
            $data['Message'] = input('message');

            $res = Db::connect("QPPlatformDB")->table('SysMessage')->insert($data);
            if ($res) {
                return $this->success('发布成功','admin/notice/index');
        } else {
                return $this->error('发布失败');
            }
        }else{
           
            $res = Db::connect("QPPlatformDB")->table('SysMessage')->order('ID desc')->paginate(20);
         
            $this->assign('res',$res); 
        }
        return $this->fetch();
    }

    public function delete(){
        $id = input('id');
        if(!$id){
           return $this->error('缺少参数');
        }
         $res = Db::connect("QPPlatformDB")->table('SysMessage')->where("ID='$id'")->delete();
          if($res){
                  return $this->success('删除成功','admin/notice/index');
            }else{
            return $this->error('删除失败');
           }
    }

    public function update(){
        if ($this->request->isPost()) {
        $id = input('id');

        $message = input('message');
        $data['Message']=$message;
         $res = Db::connect("QPPlatformDB")->table('SysMessage')->where("ID='$id'")->update($data);
           if($res){
                  return $this->success('修改成功','admin/notice/index');
            }else{
            return $this->error('修改失败');
           }
       }else{
         $id = input('id');
           $res = Db::connect("QPPlatformDB")->table('SysMessage')->where("ID='$id'")->find();
           $this->assign('res',$res);
  
       }

   return $this->fetch();
    }

  public function add(){
     
   return $this->fetch();
    }














}